package com.repair.base.result;

import com.repair.base.utils.ResponseCode;
import lombok.Getter;
import lombok.Setter;

/**
 * @author chunyu
 * @since 2024/9/13,08:08
 */
@Getter
@Setter
public class JsonResult<T> {

    private Integer code;

    private String message;

    private T data;

    public JsonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public JsonResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public JsonResult(ResponseCode responseCode, T data) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = data;
    }

    public static <T> JsonResult<T> ok(T data) {
        return new JsonResult<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), data);
    }

    public static <T> JsonResult<T> ok() {
        return ok(null);
    }

    public static <T> JsonResult<T> error(Integer errorCode, String errorMsg) {
        return new JsonResult<T>(errorCode, errorMsg);
    }

}
